﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace _344A
{
    public partial class ViewBookings : System.Web.UI.Page
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Database1ConnectionString"].ConnectionString);
        SqlDataAdapter DB;
        DataSet DS = new DataSet();
        DataTable DT = new DataTable(); //the above are all SQL connection objects for the TDG
        protected void Page_Load(object sender, EventArgs e)
        {
            SetName.InnerHtml = "Bookings for Event ID " + Request.QueryString["id"];
            getEvent();
        }

        public void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void getEvent()
        {
            con.Open();
            string CommandText = "select * from Event where id =\'" + Request.QueryString["id"] + "\';";    //attempt to get the event data from the SQL server
            try
            {
                DB = new SqlDataAdapter(CommandText, con);
                DS.Reset();
                DB.Fill(DT);
                DataRow DR = DT.Rows[0];
                ename.InnerHtml = DR.Field<string>("title");                                 //update these values in the view
                ehall.InnerHtml = DR.Field<string>("hall");
                edate.InnerHtml = Convert.ToString(DR.Field<DateTime>("date"));
                edur.InnerHtml = Convert.ToString(DR.Field<TimeSpan>("time"));
            }
            catch
            {
                SetName.Style.Add("color", "red");
                SetName.InnerHtml = "Connection to Database Failed! Please check that a valid Event was selected, or contact support.";
            }
            con.Close();
        }
    }
}